<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/gray/easyui.css">

	<div class="page-title">
		<h2><?=$title?></h2>
	</div>
<div class="box">


	<form action="<?=base_url()?>index.php/jc/journey/smile">

	<table class="general alignleft">
		<thead>
			<tr>
				<th>Territory</th>
				<th><?php echo $region.', '.$cluster;?></th>
			</tr>
		</thead>

		<tr>
			<td>Smartfren Ambassador</td>
			<td>
				<select name="sales_id" id="sales-id">
					<option value="">Pilih SFA</option>
          <?php foreach ($sfa as $key) : ?>
              <option value="<?php echo $key->user_group_id.'_'.$key->user_id; ?>" ><?php echo $key->user_id.' | '.$key->user_name; ?></option>
          <?php endforeach; ?>
				</select>
			</td>
		</tr>
		<tr>
			<td>Tanggal Referensi</td>
			<td>
				<select name="month" id="month" class="d_jc_sml">
				<?php 
					foreach ($months as $key ) {

						if (date('Ym') == $key[0]) 
							echo '<option value="'.$key[0].'" selected="selected">'.$key[1].'</option>';
						else
							echo '<option value="'.$key[0].'">'.$key[1].'</option>';
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
				<div id="button">
					<button id="show-jc">Show JC</button>
				</div>
			</td>
		</tr>
	</table>

	</form>

	<div id="jc-table">

	</div>

	<div id="populate">
		<img src="<?=base_url()?>file/images/spinner.gif"> Populate Journey Cycle
	</div>

</div> <!-- Box -->

<script type="text/javascript">
	$(document).ready(function() {

		$('#populate').hide(); //$('#pesan').hide();
		$("#show-jc").click(function(event){
			if( $('#sales-id').val() == '' || $('#sales-id').val() == null || $('#selling-type').val() == 0 ) 
				{ 
					event.preventDefault();
					alert('Nama Sales \n tidak boleh kosong'); 
				}
			else 
			{
				var sales_id = $('#sales-id').val().split('_');
				var month		 = $('#month').val();

				event.preventDefault();
				$('#jc-table').empty(); $('#populate').show();
				$.post(
					// '<?=base_url()?>index.php/jc/journey/smile',
          '<?=base_url()?>index.php/jc/load_journey',
					{sales_id:sales_id[1],user_group_id:sales_id[0],month_work:month},
					// {sales_id:sales_id,month_work:month},
					function(data) {
						if(data.channels_maintained == 0 ) {
							$('#jc-table').show(); $('#populate').hide();
							$('#jc-table').html('Tidak ada Outlet yang dikelola');
						}
						else {
							$('#jc-table').show(); $('#populate').hide();
							$('#jc-table').html(data.journey_summary);
							
						}
					},"json"
				).error(function() {
					$('#jc-table').show(); $('#populate').hide();
					$('#jc-table').html('Wrong Format');
				});
			}
		});
	});
	
</script>